﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DLL;
using PagedList;

namespace BLL
{
    public class ProductService
    {
        private ProductRepo m_Repo;

        public ProductService()
        {
            m_Repo = new ProductRepo();
        }

        public ProductService(string connectionString)
        {
            m_Repo = new ProductRepo(connectionString);
        }

        public IList<Product> GetProducts(bool all = false)
        {
            return m_Repo.GetProducts(all);
        }

        public Product GetProductById(int productId)
        {
            return m_Repo.GetProductById(productId);
        }

        public Product GetProductByName(string name)
        {
            return m_Repo.GetProductByName(name);
        }

        public pGetProductByBarcode_Result1 GetProductByBarcode(string barcode)
        {
            return m_Repo.GetProductByBarcode(barcode);
        }

        public IList<Product> GetProductsByType(int productTypeId)
        {
            return m_Repo.GetProductsByType(productTypeId);
        }

        public IList<Product> GetProductsByProducer(int producerId)
        {
            return m_Repo.GetProductsByProducer(producerId);
        }

        public IList<Product> GetProductsByTypeAndProducer(int productTypeId, int producerId, bool all = false)
        {
            return m_Repo.GetProductsByTypeAndProducer(productTypeId, producerId, all);
        }

        public List<pSellProducts_Result> GetProductsAndSellAmount()
        {
            return m_Repo.GetProductsAndSellAmount();
        }

        public List<pSellProductInDay_Result> GetSellProductInDay(int productId, DateTime? fromDate, DateTime? toDate)
        {
            return m_Repo.GetSellProductInDay(productId, fromDate, toDate);
        }

        public void AddProduct(Product product)
        {
            m_Repo.AddProduct(product);
        }

        public void UpdateProduct(Product product)
        {
            m_Repo.UpdateProduct(product);
        }

        public List<pStatisticProduct_Result> StatisticsProduct(
           out int totalInputPrice,
           string productTypeId = null, int? producerId = null, string name = null,
           bool checkWarningAmount = false, bool inputPriceChanged = false)
        {
            return m_Repo.StatisticsProduct(out totalInputPrice,
                productTypeId, producerId, name, checkWarningAmount, inputPriceChanged);
        }

        public List<pGetProductByCriteria_Result> GetProductByCriteria(
                int? productTypeId = null, int? producerId = null, string name = null,
                bool checkNotSalePrice = false, bool chechNotListedPrice = false, bool checkNotWarrantyTime = false,
                int? addBy = null, DateTime? fromDate = null, DateTime? toDate = null,
                bool checkInputPriceChanged = false, int? priceDiffFrom = null, int? priceDiffTo = null)
        {
            return m_Repo.GetProductByCriteria(
                productTypeId, producerId, name,
                checkNotSalePrice, chechNotListedPrice, checkNotWarrantyTime,
                addBy, fromDate, toDate, checkInputPriceChanged, priceDiffFrom, priceDiffTo);
        }

        public List<pGetProductHasPriceIsNotGood_Result> GetProductHasPriceNotGood()
        {
            return m_Repo.GetProductHasPriceNotGood();
        }

        public void DeleteProduct(int productId)
        {
            m_Repo.DeleteProduct(productId);
        }
    }
}
